package com.maimang.platform.dsp.controller;

import com.maimang.platform.annotation.Log;
import com.maimang.platform.base.BaseController;
import com.maimang.platform.base.Result;
import com.maimang.platform.common.utils.ExcelUtil;
import com.maimang.platform.dsp.entity.AdvertiserIds;
import com.maimang.platform.dsp.service.AdvertiserIdsService;
import com.maimang.platform.enums.BusinessType;
import com.maimang.platform.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Rocky
 * @version 1.0.0
 * @classname AdvertiserIdsController
 * @description <br>广告主列信息操作处理</br>
 * @date 2019-11-01 11:36:12
 * @email jintaozhao@qq.com
 */
@Controller
@RequestMapping("/dsp/advertiserIds")
@Api(value = "广告主列", description = "广告主列 信息操作处理接口")
public class AdvertiserIdsController extends BaseController {
	private String prefix = "dsp/advertiserIds";

	@Autowired
	private AdvertiserIdsService advertiserIdsService;

	@RequiresPermissions("dsp:advertiserIds:view")
	@GetMapping()
	public String advertiserIds() {
		return prefix + "/advertiserIds";
	}

	/**
	 * 查询广告主列列表
	 */
	@ApiOperation(value = "查询列表", notes = "查询广告主列列表信息")
	@RequiresPermissions("dsp:advertiserIds:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AdvertiserIds advertiserIds) {
		startPage();
		List<AdvertiserIds> list = advertiserIdsService.selectAdvertiserIdsList(advertiserIds);
		return getDataTable(list);
	}


	/**
	 * 导出广告主列列表
	 */
	@ApiOperation(value = "导出列表", notes = "导出广告主列列表信息到Excel文件")
	@RequiresPermissions("dsp:advertiserIds:export")
	@PostMapping("/export")
	@ResponseBody
	public Result export(AdvertiserIds advertiserIds) {
		List<AdvertiserIds> list = advertiserIdsService.selectAdvertiserIdsList(advertiserIds);
		ExcelUtil<AdvertiserIds> util = new ExcelUtil<AdvertiserIds>(AdvertiserIds.class);
		return util.exportExcel(list, "advertiserIds");
	}

	/**
	 * 新增广告主列
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存广告主列
	 */
	@ApiOperation(value = "新增保存", notes = "参数：AdvertiserIds")
	@RequiresPermissions("dsp:advertiserIds:add")
	@Log(title = "广告主列", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(AdvertiserIds advertiserIds) {
		return toResult(advertiserIdsService.insertAdvertiserIds(advertiserIds));
	}

	/**
	 * 修改广告主列
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap modelMap) {
		AdvertiserIds advertiserIds = advertiserIdsService.selectAdvertiserIdsById(id);
		modelMap.put("advertiserIds", advertiserIds);
		return prefix + "/edit";
	}

	/**
	 * 修改保存广告主列
	 */
	@ApiOperation(value = "修改保存", notes = "参数：AdvertiserIds")
	@RequiresPermissions("dsp:advertiserIds:edit")
	@Log(title = "广告主列", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(AdvertiserIds advertiserIds) {
		return toResult(advertiserIdsService.updateAdvertiserIds(advertiserIds));
	}

	/**
	 * 删除广告主列
	 */
	@ApiOperation(value = "删除对象", notes = "参数：ids，示例： id1,id2,id3，接口会转转为String[]类型")
	@RequiresPermissions("dsp:advertiserIds:remove")
	@Log(title = "广告主列", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public Result remove(String ids) {
		return toResult(advertiserIdsService.deleteAdvertiserIdsByIds(ids));
	}

}